﻿using System;
using System.Collections;
using System.Configuration;
using AddressBook.DAO;
using AddressBook.Entity;
using System.Text;

public partial class UpdateContactInfo : System.Web.UI.Page
{
    static Base_EmployeeDAO dao = new Base_EmployeeDAO();

    protected void Page_Load(object sender, EventArgs e)
    {
        ResultEntity result = new ResultEntity();
        result.Name = "UpdateContactInfo";

        if (!string.IsNullOrEmpty(Request.QueryString["contactid"]) && !string.IsNullOrEmpty(Request.QueryString["phone"]) && !string.IsNullOrEmpty(Request.QueryString["contents"]))
        {
            Guid employeeid;
            if (Guid.TryParse(Request.QueryString["contactid"], out employeeid))
            {
                Base_Employee employ = dao.GetInfoByKey(employeeid);

                if (employ != null)
                {
                    if (!employ.isDelete)
                    {
                        string contents = Request.QueryString["contents"];
                        Hashtable table = new Hashtable();
                        foreach (string property in contents.Split(','))
                        {
                            //"name":"andy"
                            string[] values = property.Split(':');
                            table.Add(values[0].Trim('"'), values[1].Trim('"'));
                        }

                        employ.Address = table["Address"].ToString();
                        employ.Email = table["Email"].ToString();
                        employ.FamiryTel = table["FamiryTel"].ToString();
                        employ.Fax = table["Fax"].ToString();
                        employ.HeadUrl = table["HeadUrl"].ToString();
                        employ.Sex = Boolean.Parse(table["Sex"].ToString());
                        employ.FstName = table["FstName"].ToString();
                        employ.SecName = table["SecName"].ToString();
                        employ.Station = table["Station"].ToString();
                        employ.Tel = table["Tel"].ToString();
                        employ.Property = table["Property"].ToString();
                        employ.UpdateTime = DateTime.Now;

                        if (dao.UpdateData(employ) > 0)
                        {
                            result.ResultCode = "0";
                        }
                        else
                        {
                            result.Desc = "修改失败！";
                            result.ResultCode = "-3";
                        }
                    }
                    else
                    {
                        result.Desc = "该用户已被删除！";
                        result.ResultCode = "-1";
                    }
                }
                else
                {
                    result.Desc = "用户不存在！";
                    result.ResultCode = "-1";
                }
            }
            else
            {
                result.Desc = "参数不正确！";
                result.ResultCode = "-2";
            }
        }
        else
        {
            result.Desc = "参数不正确！";
            result.ResultCode = "-2";
        }

        Response.Write(Common.ReturnResult(result));
    }
}
